<!doctype html>



  


<html class="theme-next muse use-motion">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  
    
      
    

    
  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Microsoft YaHei:300,300italic,400,400italic,700,700italic|consolas:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.0.2" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="tools,npm," />








  <link rel="shortcut icon" type="image/x-icon" href="http://ofy7k3v4s.bkt.clouddn.com/mylogo.png?v=5.0.2" />






<meta name="description" content="&amp;#x5305;&amp;#x5176;&amp;#x5B9E;&amp;#x5C31;&amp;#x662F;&amp;#x4E00;&amp;#x4E9B;&amp;#x6A21;&amp;#x5757;&amp;#x7EC4;&amp;#x7EC7;&amp;#x5230;&amp;#x4E00;&amp;#x8D77;&amp;#xFF0C;&amp;#x653E;&amp;#x5230;&amp;#x4E00;&amp;#x4E2A;&amp;#x76EE;&amp;#x5F55;&amp;#x4E2D;&amp;#x7684;&amp;#x4E00;&amp;#x4E2A;">
<meta property="og:type" content="article">
<meta property="og:title" content="npm, Node Package Manager">
<meta property="og:url" content="https://hongqinma.github.io/2016/11/09/t9-npm/index.html">
<meta property="og:site_name" content="HongqinMa' Blog">
<meta property="og:description" content="&amp;#x5305;&amp;#x5176;&amp;#x5B9E;&amp;#x5C31;&amp;#x662F;&amp;#x4E00;&amp;#x4E9B;&amp;#x6A21;&amp;#x5757;&amp;#x7EC4;&amp;#x7EC7;&amp;#x5230;&amp;#x4E00;&amp;#x8D77;&amp;#xFF0C;&amp;#x653E;&amp;#x5230;&amp;#x4E00;&amp;#x4E2A;&amp;#x76EE;&amp;#x5F55;&amp;#x4E2D;&amp;#x7684;&amp;#x4E00;&amp;#x4E2A;">
<meta property="og:updated_time" content="2016-11-09T11:36:38.043Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="npm, Node Package Manager">
<meta name="twitter:description" content="&amp;#x5305;&amp;#x5176;&amp;#x5B9E;&amp;#x5C31;&amp;#x662F;&amp;#x4E00;&amp;#x4E9B;&amp;#x6A21;&amp;#x5757;&amp;#x7EC4;&amp;#x7EC7;&amp;#x5230;&amp;#x4E00;&amp;#x8D77;&amp;#xFF0C;&amp;#x653E;&amp;#x5230;&amp;#x4E00;&amp;#x4E2A;&amp;#x76EE;&amp;#x5F55;&amp;#x4E2D;&amp;#x7684;&amp;#x4E00;&amp;#x4E2A;">



<script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Muse',
    sidebar: {"position":"left","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '6347850919329138000',
      author: 'Hiraku'
    }
  };
</script>




  <link rel="canonical" href="https://hongqinma.github.io/2016/11/09/t9-npm/"/>


  <title> npm, Node Package Manager | HongqinMa' Blog </title>
</head>

<body itemscope itemtype="//schema.org/WebPage" lang="en">

  



  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "//hm.baidu.com/hm.js?10010323";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>








  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="//schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta custom-logo">
  
    <div class="site-meta-headline">
      <a>
        <img class="custom-logo-image" src="http://ofy7k3v4s.bkt.clouddn.com/photo.jpg"
             alt="HongqinMa' Blog"/>
      </a>
    </div>
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">HongqinMa' Blog</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">Spell at all costs， to rush you in the future。</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            Home
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            Categories
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            Archives
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            Tags
          </a>
        </li>
      

      
    </ul>
  

  
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="//schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                npm, Node Package Manager
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">Posted on</span>
            <time itemprop="dateCreated" datetime="2016-11-09T19:33:06+08:00" content="2016-11-09">
              2016-11-09
            </time>
          </span>

          
            <span class="post-category" >
              &nbsp; | &nbsp;
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">In</span>
              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/Web-Development-Tools/" itemprop="url" rel="index">
                    <span itemprop="name">Web Development Tools</span>
                  </a>
                </span>

                
                

              
            </span>
          

          
            
              <span class="post-comments-count">
                &nbsp; | &nbsp;
                <a href="/2016/11/09/t9-npm/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="2016/11/09/t9-npm/" itemprop="commentsCount"></span>
                </a>
              </span>
            
          

          

          
          
             <span id="/2016/11/09/t9-npm/" class="leancloud_visitors" data-flag-title="npm, Node Package Manager">
               &nbsp; | &nbsp;
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               <span class="post-meta-item-text">visitors </span>
               <span class="leancloud-visitors-count"></span>
              </span>
          

          
              &nbsp; | &nbsp;
              <span class="page-pv"><i class="fa fa-file-o"></i>
              <span class="busuanzi-value" id="busuanzi_value_page_pv" ></span>
              </span>
          

          
          <span id="busuanzi_container_page_pv">  <span id="busuanzi_value_page_pv"></span> Views</span>
          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>&#x5305;&#x5176;&#x5B9E;&#x5C31;&#x662F;&#x4E00;&#x4E9B;&#x6A21;&#x5757;&#x7EC4;&#x7EC7;&#x5230;&#x4E00;&#x8D77;&#xFF0C;&#x653E;&#x5230;&#x4E00;&#x4E2A;&#x76EE;&#x5F55;&#x4E2D;&#x7684;&#x4E00;&#x4E2A;&#x79F0;&#x547C;&#xFF0C;&#x53EB;&#x5305;&#x6216;&#x8005;&#x6A21;&#x5757;&#x90FD;&#x884C;&#x3002;<br>Node Package Manager: npm &#x662F;&#x4E00;&#x4E2A;&#x7528;&#x6765;&#x5B89;&#x88C5;&#x548C;&#x7BA1;&#x7406;Node&#x5305;&#x548C;&#x524D;&#x7AEF;&#x5305;&#x7684;&#x4E00;&#x4E2A;&#x5DE5;&#x5177;</p>
<h2 id="npm-&#x6709;&#x4E24;&#x5C42;&#x542B;&#x4E49;&#xFF1A;"><a href="#npm-&#x6709;&#x4E24;&#x5C42;&#x542B;&#x4E49;&#xFF1A;" class="headerlink" title="npm &#x6709;&#x4E24;&#x5C42;&#x542B;&#x4E49;&#xFF1A;"></a>npm &#x6709;&#x4E24;&#x5C42;&#x542B;&#x4E49;&#xFF1A;</h2><ul>
<li><a href="http://www.npmjs.com/" target="_blank" rel="external">npm &#x5B98;&#x65B9;&#x7F51;&#x7AD9;</a> <ul>
<li>&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x4E2A;&#x7528;&#x6765;&#x5171;&#x6027;&#x6216;&#x8005;&#x68C0;&#x7D22;&#x7684;&#x4E00;&#x4E2A;&#x5E73;&#x53F0;</li>
<li>&#x4E00;&#x662F;&#x6258;&#x7BA1; node &#x73AF;&#x5883;&#x6216;&#x8005;&#x6D4F;&#x89C8;&#x5668;&#x73AF;&#x5883;&#x7528;&#x7684;&#x7684;&#x4E00;&#x4E9B;&#x7B2C;&#x4E09;&#x65B9;&#x5305;</li>
</ul>
</li>
<li>&#x662F;&#x4E00;&#x4E2A;&#x547D;&#x4EE4;&#x884C;&#x7BA1;&#x7406;&#x5DE5;&#x5177;&#xFF0C;&#x53EF;&#x4EE5;&#x7528;&#x6765;&#x4E0B;&#x8F7D; npm &#x7F51;&#x7AD9;&#x4E0A;&#x6258;&#x7BA1;&#x7684;&#x5305;<ul>
<li>CLI: Command Line Interface &#x547D;&#x4EE4;&#x884C;&#x7A97;&#x53E3;</li>
<li>GUI: &#x56FE;&#x5F62;&#x5316;&#x754C;&#x9762;</li>
</ul>
</li>
</ul>
<h2 id="&#x5B89;&#x88C5;-npm"><a href="#&#x5B89;&#x88C5;-npm" class="headerlink" title="&#x5B89;&#x88C5; npm"></a>&#x5B89;&#x88C5; npm</h2><p>Node &#x662F;&#x4E00;&#x4E2A;&#x6267;&#x884C;&#x73AF;&#x5883;&#xFF0C;Node &#x53EF;&#x4EE5;&#x7528;&#x6765;&#x6267;&#x884C; JavaScript &#x4EE3;&#x7801;&#xFF0C;<br>&#xFF08;&#x8FD9;&#x91CC;&#x7684;JS&#x6307;&#x7684;&#x662F; ECMAScript&#xFF09;&#xFF0C;npm &#x57FA;&#x4E8E; node &#x73AF;&#x5883;&#x7684; API<br>&#xFF08;&#x7F51;&#x7EDC;&#x64CD;&#x4F5C;API&#x3001;&#x6587;&#x4EF6;&#x64CD;&#x4F5C;API&#xFF09;&#x7F16;&#x5199;&#x7684;&#x5DE5;&#x5177;&#xFF0C;&#x53EF;&#x4EE5;&#x7528;&#x6765;&#x4E0B;&#x8F7D;&#x7B2C;&#x4E09;&#x65B9;&#x5305;&#x5230;&#x6307;&#x5B9A;&#x7684;&#x76EE;&#x5F55;&#x4E2D;&#x3002;</p>
<p>&#x5FC5;&#x987B;&#x8981;&#x5B89;&#x88C5; node &#x73AF;&#x5883;&#xFF0C;&#x6D4B;&#x8BD5;&#x662F;&#x5426;&#x6709; node &#x73AF;&#x5883;&#xFF1A;</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">node -v</div></pre></td></tr></table></figure>
<p>&#x5B89;&#x88C5;node&#x73AF;&#x5883;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x5DF2;&#x7ECF;&#x81EA;&#x52A8;&#x5B89;&#x88C5;&#x4E86; npm &#x547D;&#x4EE4;&#x884C;&#x5DE5;&#x5177;&#xFF0C;<br>&#x4E0D;&#x9700;&#x8981;&#x5355;&#x72EC;&#x5B89;&#x88C5;&#x3002;&#x53EF;&#x4EE5;&#x901A;&#x8FC7; <code>npm -v</code> &#x6D4B;&#x8BD5;npm&#x662F;&#x5426;&#x53EF;&#x7528;</p>
<h2 id="npm-&#x57FA;&#x672C;&#x4F7F;&#x7528;"><a href="#npm-&#x57FA;&#x672C;&#x4F7F;&#x7528;" class="headerlink" title="npm &#x57FA;&#x672C;&#x4F7F;&#x7528;"></a>npm &#x57FA;&#x672C;&#x4F7F;&#x7528;</h2><h3 id="&#x672C;&#x5730;&#x5B89;&#x88C5;"><a href="#&#x672C;&#x5730;&#x5B89;&#x88C5;" class="headerlink" title="&#x672C;&#x5730;&#x5B89;&#x88C5;"></a>&#x672C;&#x5730;&#x5B89;&#x88C5;</h3><p>&#x4E00;&#x822C;&#x662F;&#x5728;&#x9879;&#x76EE;&#x4E2D;&#xFF0C;&#x5B89;&#x88C5;&#x9879;&#x76EE;&#x4F7F;&#x7528;&#x7684;&#x4F9D;&#x8D56;&#x5305;&#xFF0C;&#x4F8B;&#x5982; underscore&#x3001;less&#x3001;jQuery&#xFF0C;<br>&#x53EF;&#x4EE5;&#x5728;&#x7EC8;&#x7AEF;&#x4E2D;&#xFF0C;&#x5207;&#x6362;&#x5230;&#x9879;&#x76EE;&#x7684;&#x6839;&#x76EE;&#x5F55;&#xFF0C;&#x7136;&#x540E;&#x6267;&#x884C; <code>npm install &#x5305;&#x540D;</code>&#xFF0C;<br>&#x6BD4;&#x5982;&#xFF1A;<code>npm install jquery</code><br>npm &#x5DE5;&#x5177;&#x4F1A;&#x81EA;&#x52A8;&#x5C06; jQuery &#x8FD9;&#x4E2A;&#x5305;&#x4E0B;&#x8F7D;&#xFF0C;&#x7136;&#x540E;&#x653E;&#x5230; <code>node_modules</code> &#x76EE;&#x5F55;&#x4E2D;&#x3002;<br>node_modules &#x76EE;&#x5F55;&#x5982;&#x679C;&#x4E0D;&#x5B58;&#x5728;&#x4F1A;&#x65B0;&#x5EFA;&#xFF0C;&#x5982;&#x679C;&#x5DF2;&#x5B58;&#x5728;&#xFF0C;&#x5219;&#x76F4;&#x63A5;&#x5C06;&#x4E0B;&#x8F7D;&#x7684;&#x5305;&#x653E;&#x5230;&#x8BE5;&#x76EE;&#x5F55;&#x4E2D;&#x3002;</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">npm install [--save] &#x5305;&#x540D;</div></pre></td></tr></table></figure>
<p>&#x8FD9;&#x884C;&#x547D;&#x4EE4;&#x8DDF;&#x5305;&#x8BF4;&#x660E;&#x6587;&#x4EF6;<code>package.json</code> &#x6709;&#x5343;&#x4E1D;&#x4E07;&#x7F15;&#x7684;&#x5173;&#x7CFB; </p>
<h3 id="&#x5305;&#x8BF4;&#x660E;&#x6587;&#x4EF6;&#xFF1A;package-json"><a href="#&#x5305;&#x8BF4;&#x660E;&#x6587;&#x4EF6;&#xFF1A;package-json" class="headerlink" title="&#x5305;&#x8BF4;&#x660E;&#x6587;&#x4EF6;&#xFF1A;package.json"></a>&#x5305;&#x8BF4;&#x660E;&#x6587;&#x4EF6;&#xFF1A;package.json</h3><p>&#x5305;&#x8BF4;&#x660E;&#x6587;&#x4EF6;&#x5176;&#x5B9E;&#x5C31;&#x662F;&#x4E00;&#x4E2A;&#x4EA7;&#x54C1;&#x7684;&#x8BF4;&#x660E;&#x4E66;&#xFF1A;<code>package.json</code> &#x6587;&#x4EF6;&#x3002;<br>&#x8BE5;&#x6587;&#x4EF6;&#x4E00;&#x822C;&#x53EA;&#x5B58;&#x5728;&#x4E8E;&#x9879;&#x76EE;&#x7684;&#x6839;&#x8DEF;&#x5F84;&#x4E0B;&#xFF0C;<br>&#x5B9A;&#x4E49;&#x4E86;&#x8FD9;&#x4E2A;&#x9879;&#x76EE;&#x6240;&#x9700;&#x8981;&#x7684;&#x5404;&#x79CD;&#x6A21;&#x5757;&#xFF0C;<br>&#x4EE5;&#x53CA;&#x9879;&#x76EE;&#x7684;&#x914D;&#x7F6E;&#x4FE1;&#x606F;&#xFF08;&#x6BD4;&#x5982;&#x540D;&#x79F0;&#x3001;&#x7248;&#x672C;&#x3001;&#x4F9D;&#x8D56;&#x9879;&#x7B49;&#x4FE1;&#x606F;&#xFF09;&#x3002;<br>&#x53EF;&#x4EE5;&#x901A;&#x8FC7; <code>npm init [-y]</code> &#x547D;&#x4EE4;&#x4F7F;&#x7528;&#x5411;&#x5BFC;&#x7684;&#x5F62;&#x5F0F;&#x521B;&#x5EFA;&#x8BE5;&#x6587;&#x4EF6;&#x3002;</p>
<p>&#x8BE5;&#x6587;&#x4EF6;&#x4E2D;&#x63CF;&#x8FF0;&#x4E86;&#x9879;&#x76EE;&#x7684;&#x4E00;&#x4E9B;&#x5143;&#x6570;&#x636E;&#xFF0C;&#x4F8B;&#x5982; <code>name&#x3001;version&#x3001;author</code> &#x7B49;&#x4FE1;&#x606F;&#x3002;</p>
<p>&#x5176;&#x4E2D;&#x6709;&#x4E00;&#x4E2A;&#x975E;&#x5E38;&#x91CD;&#x8981;&#x7684;&#x5C5E;&#x6027;&#xFF0C;&#x53EB;&#x505A;&#xFF1A;<code>dependencies</code>&#xFF0C;&#x8BE5;&#x5C5E;&#x6027;&#x662F;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#xFF0C;<br>&#x91CC;&#x9762;&#x4FDD;&#x5B58;&#x4E86;&#x5F53;&#x524D;&#x9879;&#x76EE;&#x7684;&#x4F9D;&#x8D56;&#x9879;&#xFF0C;&#x8BE5;&#x5B57;&#x6BB5;&#x4E00;&#x822C;&#x4E0D;&#x8981;&#x624B;&#x52A8;&#x4FEE;&#x6539;&#xFF0C;<br>&#x5B83;&#x9700;&#x8981;&#x7ED3;&#x5408; <code>npm install --save &#x5305;&#x540D;</code> &#x6765;&#x4F7F;&#x7528;&#xFF0C;<br>&#x53EA;&#x8981;&#x5728;&#x5B89;&#x88C5;&#x7684;&#x65F6;&#x5019;&#x52A0;&#x4E0A; <code>--save</code> &#x53C2;&#x6570;&#x5C31;&#x4F1A;&#x81EA;&#x52A8;&#x5C06;&#x5305;&#x4F9D;&#x8D56;&#x9879;&#x6DFB;&#x52A0;&#x5230;&#x8BE5;&#x5C5E;&#x6027;&#x4E2D;&#xFF0C;&#x5F88;&#x65B9;&#x4FBF;&#x3002;</p>
<p>&#x751A;&#x81F3;&#x8FD8;&#x53EF;&#x4EE5;&#x5B8C;&#x5168;&#x628A; <code>node_modules</code> &#x76EE;&#x5F55;&#x5220;&#x9664;&#x6389;&#xFF0C;&#x53EA;&#x8981; <code>package.json</code> &#x6587;&#x4EF6;&#x8FD8;&#x5728;&#xFF0C;<br>&#x5C31;&#x53EF;&#x4EE5;&#x6267;&#x884C; <code>npm install</code> &#x5B89;&#x88C5;&#x5305;&#x8BF4;&#x660E;&#x6587;&#x4EF6;&#x4E2D;&#x7684;&#x6240;&#x6709;&#x7684;&#x4F9D;&#x8D56;&#x9879;&#x3002;<br>&#x6267;&#x884C; <code>npm install</code> &#x547D;&#x4EE4;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x5B83;&#x4F1A;&#x81EA;&#x52A8;&#x67E5;&#x8BE2;&#x5F53;&#x524D;&#x76EE;&#x5F55;&#x4E0B;&#x7684; <code>package.json</code> &#x6587;&#x4EF6;&#xFF0C;<br>&#x7136;&#x540E;&#x627E;&#x5230;&#x91CC;&#x9762;&#x7684; <code>dependencies</code> &#x5C5E;&#x6027;&#xFF0C;&#x4F9D;&#x6B21;&#x4E0B;&#x8F7D;&#x5230; <code>node_modules</code> &#x76EE;&#x5F55;&#x4E0B;&#x3002;</p>
<p>&#x5EFA;&#x8BAE;&#xFF1A;&#x4EE5;&#x540E;&#x4F7F;&#x7528; npm &#x7684;&#x65F6;&#x5019;&#xFF0C;&#x9996;&#x5148;&#x7528; <code>npm init -y</code> &#x521D;&#x59CB;&#x5316;&#x4E00;&#x4E2A; <code>package.json</code>&#xFF0C;<br>&#x7136;&#x540E;&#x4F7F;&#x7528; <code>npm install &#x5305;&#x540D; --save</code> </p>
<p>&#x603B;&#x7684;&#x6765;&#x8BB2;&#xFF0C;&#x6709;&#x4EE5;&#x4E0B;&#x51E0;&#x4E2A;&#x6B65;&#x9AA4;&#xFF0C;&#x91CD;&#x8981;&#x7EC4;&#x6210;&#xFF1A;</p>
<ul>
<li><code>npm init [-y]</code> <ul>
<li>&#x751F;&#x6210; package.json &#x6587;&#x4EF6;</li>
</ul>
</li>
<li>main<ul>
<li>&#x7528;&#x6765;&#x6307;&#x5B9A;&#x52A0;&#x8F7D;&#x7684;&#x65F6;&#x5019;&#x7684;&#x5165;&#x53E3;&#x6A21;&#x5757;&#x7684;</li>
</ul>
</li>
<li>dependencies<ul>
<li>&#x5F53;&#x524D;&#x9879;&#x76EE;&#x6216;&#x8005;&#x8BF4;&#x5305;&#x7684;&#x4F9D;&#x8D56;&#x9879;</li>
<li>npm install &#x7684;&#x65F6;&#x5019;&#xFF0C;&#x4F1A;&#x81EA;&#x52A8;&#x67E5;&#x627E;&#x5F53;&#x524D;&#x76EE;&#x5F55;&#x4E0B;&#x7684; package.json &#x6587;&#x4EF6;&#x4E2D;&#x7684; dependencies &#x5C5E;&#x6027;</li>
<li>&#x7136;&#x540E;&#x4F9D;&#x6B21;&#x4E0B;&#x8F7D;</li>
</ul>
</li>
</ul>
<h3 id="&#x672C;&#x5730;&#x5B89;&#x88C5;&#x5E38;&#x7528;&#x547D;&#x4EE4;"><a href="#&#x672C;&#x5730;&#x5B89;&#x88C5;&#x5E38;&#x7528;&#x547D;&#x4EE4;" class="headerlink" title="&#x672C;&#x5730;&#x5B89;&#x88C5;&#x5E38;&#x7528;&#x547D;&#x4EE4;"></a>&#x672C;&#x5730;&#x5B89;&#x88C5;&#x5E38;&#x7528;&#x547D;&#x4EE4;</h3><p><code>cd Desktop\code</code><br><code>npm init</code><br><code>cls</code> &#x6E05;&#x5C4F;<br><code>npm install bootstrap --save</code><br><code>npm install --save jquery</code><br><code>npm install</code> </p>
<h3 id="&#x5168;&#x5C40;&#x5B89;&#x88C5;"><a href="#&#x5168;&#x5C40;&#x5B89;&#x88C5;" class="headerlink" title="&#x5168;&#x5C40;&#x5B89;&#x88C5;"></a>&#x5168;&#x5C40;&#x5B89;&#x88C5;</h3><p>&#x5168;&#x5C40;&#x5B89;&#x88C5;&#xFF1A; &#x4E00;&#x822C;&#x7528;&#x4E8E;&#x5B89;&#x88C5;&#x4E00;&#x4E9B;&#x547D;&#x4EE4;&#x884C;&#x5DE5;&#x5177;&#xFF08;&#x8FD9;&#x4E9B;&#x5DE5;&#x5177;&#x4E5F;&#x662F;&#x57FA;&#x4E8E;Node&#x5F00;&#x53D1;&#x7684;&#xFF09;<br>&#x5168;&#x5C40;&#x5B89;&#x88C5;&#x4F7F;&#x7528; <code>npm install --global &#x5305;&#x540D;&#xFF08;&#x5DE5;&#x5177;&#x540D;&#xFF09;</code>&#xFF0C;<br>&#x5728;&#x4EFB;&#x610F;&#x76EE;&#x5F55;&#x6267;&#x884C;&#x8BE5;&#x547D;&#x4EE4;&#x90FD;&#x53EF;&#x4EE5;&#x3002;</p>
<p>&#x6BD4;&#x5982;&#xFF1A;</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">npm i -g less</div></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">npm install -g less</div></pre></td></tr></table></figure>
<h4 id="&#x5E38;&#x7528;&#x547D;&#x4EE4;"><a href="#&#x5E38;&#x7528;&#x547D;&#x4EE4;" class="headerlink" title="&#x5E38;&#x7528;&#x547D;&#x4EE4;"></a>&#x5E38;&#x7528;&#x547D;&#x4EE4;</h4><ul>
<li><code>npm help</code> &#x67E5;&#x770B; npm &#x547D;&#x4EE4;&#x5217;&#x8868;</li>
<li><code>npm -l</code> &#x67E5;&#x770B;&#x5404;&#x4E2A;&#x547D;&#x540D;&#x7684;&#x7B80;&#x5355;&#x7528;&#x6CD5;</li>
<li><code>npm -v</code> &#x67E5;&#x770B; npm &#x7684;&#x7248;&#x672C;</li>
<li><code>npm root -g</code> &#x67E5;&#x770B;&#x5168;&#x5C40;&#x5305;&#x5B89;&#x88C5;&#x76EE;&#x5F55;&#x3002;</li>
<li><code>npm init [-y]</code>&#xFF1A;&#x521D;&#x59CB;&#x5316;&#x4E00;&#x4E2A; package.json &#x6587;&#x4EF6;</li>
<li><code>npm info</code> &#x5305;&#x540D; [&#x5B57;&#x6BB5;&#x540D;]&#xFF1A;&#x67E5;&#x770B;&#x6307;&#x5B9A;&#x6A21;&#x5757;&#x7684; package.json &#x4FE1;&#x606F;</li>
<li><code>npm search</code> &#x5305;&#x540D;&#xFF1A;&#x8BE5;&#x547D;&#x4EE4;&#x7528;&#x4E8E;&#x641C;&#x7D22; npm &#x4ED3;&#x5E93;</li>
<li><code>npm list</code> &#x4EE5;&#x6811;&#x578B;&#x7ED3;&#x6784;&#x5217;&#x51FA;&#x5F53;&#x524D;&#x9879;&#x76EE;&#x5B89;&#x88C5;&#x7684;&#x6240;&#x6709;&#x6A21;&#x5757;&#xFF0C;&#x4EE5;&#x53CA;&#x5B83;&#x4EEC;&#x4F9D;&#x8D56;&#x7684;&#x6A21;&#x5757;</li>
<li><code>npm list</code> &#x5305;&#x540D;&#xFF1A;&#x5217;&#x51FA;&#x5355;&#x4E2A;&#x6A21;&#x5757;</li>
<li><code>npm list -g</code> &#x5217;&#x51FA;&#x5168;&#x5C40;&#x5B89;&#x88C5;&#x7684;&#x6A21;&#x5757;</li>
<li><code>npm install [--save] &#x5305;&#x540D;[#&#x7248;&#x672C;&#x53F7;]</code><ul>
<li><code>npm install &#x5305;&#x540D;</code> &#x5B89;&#x88C5;&#x5305;&#x5230;&#x5F53;&#x524D;&#x9879;&#x76EE;&#x4E0B;&#x7684; node_modules &#x76EE;&#x5F55;&#x4E0B;</li>
<li><code>npm install|i --save|-S &#x5305;&#x540D;</code> &#x5B89;&#x88C5;&#x5305;&#x7684;&#x540C;&#x65F6;&#x628A;&#x4F9D;&#x8D56;&#x9879;&#x4FDD;&#x5B58;&#x5230; &#x5305;&#x8BF4;&#x660E;&#x6587;&#x4EF6;&#x4E2D;</li>
<li>&#x672C;&#x5730;&#x9879;&#x76EE;&#x5B89;&#x88C5;&#xFF1A;&#x76EE;&#x7684;&#x662F;&#x4E3A;&#x4E86;&#x8F85;&#x52A9;&#x4F60;&#x7684;&#x4EE3;&#x7801;&#x529F;&#x80FD;&#x5F00;&#x53D1;</li>
</ul>
</li>
<li><code>npm uninstall [--save] &#x5305;&#x540D;</code><ul>
<li><code>npm uninstall &#x5305;&#x540D;</code> &#x5220;&#x9664;&#x5305;&#xFF0C;&#x4F46;&#x662F;&#x5982;&#x679C;&#x5305;&#x8BF4;&#x660E;&#x6587;&#x4EF6;&#x4E2D;&#x6709;&#x4F9D;&#x8D56;&#x9879;&#xFF0C;&#x90A3;&#x4E48;&#x4E0D;&#x4F1A;&#x5220;&#x9664;</li>
<li><code>npm uninstall --save &#x5305;&#x540D;</code> &#x5220;&#x9664;&#x5305;&#xFF0C;&#x540C;&#x65F6;&#x5C06; package.json &#x6587;&#x4EF6;&#x4E2D;&#x7684;&#x4F9D;&#x8D56;&#x9879;&#x4E5F;&#x5220;&#x9664;</li>
</ul>
</li>
<li><code>npm install</code></li>
<li><code>npm install -g &#x5305;&#x540D;</code><ul>
<li>&#x5168;&#x5C40;&#x5B89;&#x88C5;&#xFF1A;&#x4E00;&#x822C;&#x7528;&#x4E8E;&#x5B89;&#x88C5;&#x547D;&#x4EE4;&#x884C;&#x4E2D;&#x7684; CLI &#x5DE5;&#x5177;</li>
</ul>
</li>
<li><code>npm uninstall -g &#x5305;&#x540D;</code></li>
<li><code>npm install -g http-server --registry=http://192.168.32.59:7001</code> &#x8BBE;&#x7F6E;&#x670D;&#x52A1;&#x5668;&#x955C;&#x50CF;&#x6E90;&#x5730;&#x5740;</li>
<li>npm config<ul>
<li><code>npm config list</code> &#x67E5;&#x770B; npm &#x914D;&#x7F6E;&#x9879;</li>
<li><code>npm config set init.author.name $name</code> &#x4F7F;&#x7528; npm init &#x65F6;&#xFF0C;&#x9ED8;&#x8BA4;&#x7684; name</li>
<li><code>npm config set init.author.email $email</code> &#x4F7F;&#x7528; npm init &#x65F6;&#xFF0C;&#x9ED8;&#x8BA4;&#x7684; email</li>
<li><code>npm congig set prefix &quot;&#x8DEF;&#x5F84;&quot;</code> &#x6539;&#x53D8;&#x5168;&#x5C40;&#x5305;&#x5B89;&#x88C5;&#x8DEF;&#x5F84;</li>
<li><code>npm config set registry</code> &#x201C;&#x955C;&#x50CF;&#x8DEF;&#x5F84;&#x201D;</li>
</ul>
</li>
<li><code>http-server</code> &#x5F00;&#x542F;&#x670D;&#x52A1;&#x5668;</li>
<li><code>http-server-o</code> &#x5F00;&#x542F;&#x670D;&#x52A1;&#x5668;&#x5E76;&#x76F4;&#x63A5;&#x5728;&#x6D4F;&#x89C8;&#x5668;&#x4E2D;&#x6253;&#x5F00;</li>
</ul>
<h2 id="&#x5982;&#x4F55;&#x5C06;&#x5305;&#x53D1;&#x5E03;&#x5230;-npm-&#x7F51;&#x7AD9;&#x4E0A;&#x5E76;&#x4E14;&#x901A;&#x8FC7;-npm-install-global-&#x5305;&#x540D;-&#x5B89;&#x88C5;"><a href="#&#x5982;&#x4F55;&#x5C06;&#x5305;&#x53D1;&#x5E03;&#x5230;-npm-&#x7F51;&#x7AD9;&#x4E0A;&#x5E76;&#x4E14;&#x901A;&#x8FC7;-npm-install-global-&#x5305;&#x540D;-&#x5B89;&#x88C5;" class="headerlink" title="&#x5982;&#x4F55;&#x5C06;&#x5305;&#x53D1;&#x5E03;&#x5230; npm &#x7F51;&#x7AD9;&#x4E0A;&#x5E76;&#x4E14;&#x901A;&#x8FC7; npm install --global &#x5305;&#x540D; &#x5B89;&#x88C5;"></a>&#x5982;&#x4F55;&#x5C06;&#x5305;&#x53D1;&#x5E03;&#x5230; npm &#x7F51;&#x7AD9;&#x4E0A;&#x5E76;&#x4E14;&#x901A;&#x8FC7; <code>npm install --global &#x5305;&#x540D;</code> &#x5B89;&#x88C5;</h2><h3 id="&#x914D;&#x7F6E;&#x539F;&#x7406;"><a href="#&#x914D;&#x7F6E;&#x539F;&#x7406;" class="headerlink" title="&#x914D;&#x7F6E;&#x539F;&#x7406;"></a>&#x914D;&#x7F6E;&#x539F;&#x7406;</h3><ul>
<li><code>npm root -g</code> </li>
<li>&#x6A21;&#x62DF;&#x8BE5;&#x76EE;&#x5F55;&#x4E0B; nrm &#x4E0B;&#x7684; cli.js (&#x5165;&#x53E3;&#x6587;&#x4EF6;) &#x6587;&#x4EF6;&#x4E2D;&#xFF0C;&#x5728;&#x7B2C;&#x4E00;&#x884C;&#x52A0;&#x5165;&#x4E86; <code>#!/usr/bin/env node</code></li>
<li>&#x5F97;&#x5230;&#x8DEF;&#x5F84;&#xFF1A;<code>C:\Users\mhq\AppData\Roaming\npm\node_modules</code></li>
<li>&#x5728;&#x6B64;&#x8DEF;&#x5F84;&#x4E0B;&#x65B0;&#x5EFA; &#x4EE5; &#x9700;&#x8981;&#x53D1;&#x5E03;&#x7684;&#x5305;&#x7684;&#x5305;&#x540D;&#x547D;&#x540D;&#x7684;&#x6587;&#x4EF6;&#xFF1A; &#x6BD4;&#x5982; <code>mCoy</code>;</li>
<li>&#x5C06;&#x6240;&#x9700;&#x8981;&#x53D1;&#x5E03;&#x7684; js &#x6587;&#x4EF6;&#x653E;&#x5230;&#x8FD9;&#x4E2A;&#x6587;&#x4EF6;&#x4E0B;&#xFF0C; &#x6BD4;&#x5982; <code>08_copy.js</code>;</li>
<li>&#x5728;&#x8BE5;&#x6587;&#x4EF6;&#x7684;&#x4E0A;&#x4E00;&#x7EA7;&#x76EE;&#x5F55;&#x4E0B;&#xFF0C;<code>C:\Users\mhq\AppData\Roaming\npm</code> &#x4E0B;&#xFF0C;&#x590D;&#x5236;&#x4E00;&#x4E2A; nrm.cmd &#x526F;&#x672C;</li>
<li>&#x91CD;&#x540D;&#x540D;&#x8BE5;&#x526F;&#x672C;&#x6587;&#x4EF6;&#x4E3A; <code>mCopy</code>, &#x73B0;&#x5728;&#x8FD9;&#x4E2A;&#x6587;&#x4EF6;&#x957F;&#x8FD9;&#x6837;&#xFF1A;</li>
</ul>
<figure class="highlight cmd"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">@<span class="keyword">IF</span> <span class="keyword">EXIST</span> &quot;%~dp0\node.exe&quot; (</div><div class="line">  &quot;%~dp0\node.exe&quot;  &quot;%~dp0\node_modules\nrm\cli.js&quot; %*</div><div class="line">) <span class="keyword">ELSE</span> (</div><div class="line">  @<span class="built_in">SETLOCAL</span></div><div class="line">  @<span class="built_in">SET</span> PATHEXT=<span class="variable">%PATHEXT:;.JS;=;%</span></div><div class="line">  node  &quot;%~dp0\node_modules\nrm\cli.js&quot; %*</div><div class="line">)</div></pre></td></tr></table></figure>
<h3 id="node-&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x4E2A;&#x66F4;&#x65B9;&#x4FBF;&#x7684;&#x65B9;&#x5F0F;&#x81EA;&#x52A8;&#x751F;&#x6210;-cmd-&#x6587;&#x4EF6;&#x4EE5;&#x53CA;&#x548C;&#x9700;&#x8981;&#x53D1;&#x5E03;&#x7684;&#x6587;&#x4EF6;&#x4EA7;&#x751F;&#x5173;&#x8054;"><a href="#node-&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x4E2A;&#x66F4;&#x65B9;&#x4FBF;&#x7684;&#x65B9;&#x5F0F;&#x81EA;&#x52A8;&#x751F;&#x6210;-cmd-&#x6587;&#x4EF6;&#x4EE5;&#x53CA;&#x548C;&#x9700;&#x8981;&#x53D1;&#x5E03;&#x7684;&#x6587;&#x4EF6;&#x4EA7;&#x751F;&#x5173;&#x8054;" class="headerlink" title="node &#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x4E2A;&#x66F4;&#x65B9;&#x4FBF;&#x7684;&#x65B9;&#x5F0F;&#x81EA;&#x52A8;&#x751F;&#x6210; .cmd &#x6587;&#x4EF6;&#x4EE5;&#x53CA;&#x548C;&#x9700;&#x8981;&#x53D1;&#x5E03;&#x7684;&#x6587;&#x4EF6;&#x4EA7;&#x751F;&#x5173;&#x8054;"></a>node &#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x4E2A;&#x66F4;&#x65B9;&#x4FBF;&#x7684;&#x65B9;&#x5F0F;&#x81EA;&#x52A8;&#x751F;&#x6210; .cmd &#x6587;&#x4EF6;&#x4EE5;&#x53CA;&#x548C;&#x9700;&#x8981;&#x53D1;&#x5E03;&#x7684;&#x6587;&#x4EF6;&#x4EA7;&#x751F;&#x5173;&#x8054;</h3><ul>
<li>&#x73B0;&#x5728;&#x5C06;&#x539F;&#x7406;&#x4E2D;&#x4ECB;&#x7ECD;&#x7684;&#x8FC7;&#x7A0B;&#x4EA7;&#x751F;&#x7684;&#x6587;&#x4EF6;&#x5220;&#x9664;&#xFF0C;&#x91CD;&#x65B0;&#x4F7F;&#x7528; Node &#x65B9;&#x5F0F;&#x914D;&#x7F6E;</li>
<li>&#x5728;&#x684C;&#x9762;&#x65B0;&#x5EFA; <code>mCopy</code> &#x6587;&#x4EF6;</li>
<li>win+R &#x2013;&gt; cmd &#x2013;&gt; cd Desktop &#x2013;&gt; cd mCopy</li>
<li>&#x65B0;&#x5EFA;&#x4E00;&#x4E2A; .js &#x7684;&#x5165;&#x53E3;&#x6587;&#x4EF6;&#xFF0C;&#x5728;&#x7B2C;&#x4E00;&#x884C;&#x52A0;&#x5165;&#x4E86; <code>#!/usr/bin/env node</code>&#xFF0C;&#x8FD9;&#x53EB;&#x8BBE;&#x7ED1;&#xFF1B;<ul>
<li>&#x8FD9;&#x4E2A;&#x6807;&#x8BB0;&#x5728; Linux &#x6216; Unix &#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#x4E0A;</li>
</ul>
</li>
<li>&#x5728; package.json &#x6587;&#x4EF6;&#x4E2D;&#x52A0;&#x5165; bin &#x5B57;&#x6BB5;&#xFF0C;<ul>
<li>bin &#x5B57;&#x6BB5;&#x662F;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;</li>
<li>&#x8BE5;&#x5BF9;&#x8C61;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x5C5E;&#x6027;&#x5C31;&#x662F;&#x6267;&#x884C;&#x811A;&#x672C;&#x6587;&#x4EF6;&#x7684;&#x547D;&#x4EE4;&#xFF0C; &#x6BD4;&#x5982; &#x201C;mCopy&#x201D;&#xFF0C;&#x7528;&#x6765;&#x751F;&#x6210; .cmd &#x6587;&#x4EF6;</li>
<li>&#x8BE5;&#x5BF9;&#x8C61;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x5C5E;&#x6027;&#x7684;&#x503C;&#x5C31;&#x662F;&#x8981;&#x6267;&#x884C;&#x7684;&#x811A;&#x672C;&#x6587;&#x4EF6;</li>
</ul>
</li>
</ul>
<p>package.json &#x6587;&#x4EF6;&#x5982;&#x4E0B;&#xFF1A;</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line">{</div><div class="line">  <span class="attr">&quot;name&quot;</span>: <span class="string">&quot;mcopy&quot;</span>,</div><div class="line">  <span class="attr">&quot;version&quot;</span>: <span class="string">&quot;1.0.0&quot;</span>,</div><div class="line">  <span class="attr">&quot;description&quot;</span>: <span class="string">&quot;&quot;</span>,</div><div class="line">  <span class="attr">&quot;main&quot;</span>: <span class="string">&quot;index.js&quot;</span>,</div><div class="line">  <span class="attr">&quot;bin&quot;</span>: {</div><div class="line">    <span class="attr">&quot;mcopy&quot;</span>: <span class="string">&quot;./index.js&quot;</span></div><div class="line">  },</div><div class="line">  <span class="attr">&quot;scripts&quot;</span>: {</div><div class="line">    <span class="attr">&quot;test&quot;</span>: <span class="string">&quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;</span></div><div class="line">  },</div><div class="line">  <span class="attr">&quot;keywords&quot;</span>: [],</div><div class="line">  <span class="attr">&quot;author&quot;</span>: <span class="string">&quot;&quot;</span>,</div><div class="line">  <span class="attr">&quot;license&quot;</span>: <span class="string">&quot;ISC&quot;</span></div><div class="line">}</div></pre></td></tr></table></figure>
<ul>
<li>&#x6700;&#x540E;&#xFF0C;&#x6253;&#x5F00;&#x7EC8;&#x7AEF;&#xFF0C;&#x8FDB;&#x5165;&#x5F53;&#x524D;&#x9879;&#x76EE;&#x7684;&#x6839;&#x8DEF;&#x5F84;&#xFF0C;&#x6267;&#x884C;&#xFF1A;<code>npm link</code><ul>
<li>&#x6267;&#x884C;&#x5B8C;&#x8BE5;&#x547D;&#x4EE4;&#x4E4B;&#x540E;&#xFF0C; node &#x4F1A;&#x81EA;&#x52A8;&#x53BB;&#x5168;&#x5C40;&#x5B89;&#x88C5;&#x521B;&#x5EFA;&#x8DEF;&#x5F84;&#x5BF9;&#x5E94;&#x7684; .cmd &#x6587;&#x4EF6;</li>
<li>&#x8FD9;&#x6837;&#x5C31;&#x5F00;&#x53D1;&#x4E86;&#x547D;&#x4EE4;&#x884C;&#x5DE5;&#x5177;</li>
<li>&#x5982;&#x679C;&#x60F3;&#x5378;&#x8F7D;&#x6389;&#xFF0C;&#x4F7F;&#x7528;&#x547D;&#x4EE4; <code>npm unlink</code></li>
<li>&#x65B0;&#x5EFA;&#x4E00;&#x4E2A; .js &#x6587;&#x4EF6;&#xFF0C;&#x5C06;&#x9700;&#x8981;&#x53D1;&#x5E03;&#x7684;&#x5305;&#x7684;&#x4EE3;&#x7801;&#x653E;&#x8FDB;&#x53BB;&#xFF1B;&#x6BD4;&#x5982;&#xFF1A;<code>copy.js</code></li>
</ul>
</li>
</ul>
<p>copy.js &#x6587;&#x4EF6;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">const</span> fs = <span class="built_in">require</span>(<span class="string">&apos;fs&apos;</span>);</div><div class="line"><span class="comment">// &#x66B4;&#x9732;&#x63A5;&#x53E3;</span></div><div class="line"><span class="built_in">module</span>.exports = <span class="function"><span class="keyword">function</span> (<span class="params">src, des, callback</span>) </span>{</div><div class="line">    fs.readFile(src, (err, data) =&gt; {</div><div class="line">        <span class="keyword">if</span> (err) {</div><div class="line">            <span class="keyword">return</span> callback(err);</div><div class="line">        }</div><div class="line">        fs.writeFile(des, data, err =&gt; {</div><div class="line">            <span class="keyword">return</span> callback(err);</div><div class="line">        });</div><div class="line">        callback(<span class="literal">null</span>);</div><div class="line">    });</div><div class="line">};</div></pre></td></tr></table></figure>
<p>index.js &#x6587;&#x4EF6;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line"><span class="meta">#!/usr/bin/env node</span></div><div class="line"><span class="keyword">const</span> copy = <span class="built_in">require</span>(<span class="string">&apos;./copy&apos;</span>);</div><div class="line"><span class="keyword">const</span> args = process.argv.slice(<span class="number">2</span>);</div><div class="line"><span class="built_in">console</span>.log(args);</div><div class="line">copy(args[<span class="number">0</span>], args[<span class="number">1</span>], err =&gt; {</div><div class="line">  <span class="keyword">if</span> (err) {</div><div class="line">    <span class="keyword">return</span> <span class="built_in">console</span>.log(<span class="string">&apos;Copy Fail&apos;</span>);</div><div class="line">  }</div><div class="line">  <span class="built_in">console</span>.log(<span class="string">&apos;Copy Success&apos;</span>);</div><div class="line">});</div></pre></td></tr></table></figure>
<ul>
<li>&#x53D1;&#x5E03;<ul>
<li>&#x53D1;&#x5E03;&#x4E4B;&#x524D;&#x5148;&#x53BB; npmjs.com &#x4E0A;&#x9A8C;&#x8BC1;&#x4E00;&#x4E0B;&#x4F60;&#x7684; package.json &#x4E2D;&#x7684; name &#x662F;&#x5426;&#x88AB;&#x5360;&#x7528;</li>
<li>&#x5982;&#x679C;&#x88AB;&#x5360;&#x7528;&#xFF0C;&#x5219;&#x4FEE;&#x6539; name </li>
<li>&#x6CE8;&#x610F;&#xFF1A;&#x6539;&#x4E86;&#x540D;&#x5B57;&#x4E4B;&#x540E;&#x5C31;&#x65E0;&#x6CD5;&#x5378;&#x8F7D;&#x3002;<ul>
<li>&#x4E00;&#x79CD;&#x65B9;&#x5F0F;&#x662F;&#x76F4;&#x63A5;&#x5220;&#x6389;</li>
<li>&#x4E00;&#x79CD;&#x65B9;&#x5F0F;&#x662F;&#x628A; package.json &#x6587;&#x4EF6;&#x4E0B;&#x7684; name &#x6539;&#x56DE;&#x539F;&#x6765;&#x7684;&#x7136;&#x540E;&#x518D;&#x4F7F;&#x7528; <code>npm unlink</code> &#x5378;&#x8F7D;</li>
<li>&#x7136;&#x540E;&#x628A; name &#x6539;&#x6210;&#x7EBF;&#x4E0A;&#x6CA1;&#x6709;&#x7684;&#x540D;&#x5B57;</li>
</ul>
</li>
<li>&#x53BB; <a href="https://www.npmjs.com" target="_blank" rel="external">https://www.npmjs.com</a> &#x5B98;&#x7F51;&#x6CE8;&#x518C;&#x4E00;&#x4E2A;&#x8D26;&#x53F7;&#xFF0C;&#x6216;&#x8005;&#x901A;&#x8FC7; npm adduser &#x6CE8;&#x518C;&#x4E00;&#x4E2A;&#x8D26;&#x6237;</li>
<li>&#x6CE8;&#x610F;&#xFF1A;&#x8FD9;&#x91CC;&#x4E00;&#x5B9A;&#x8981;&#x786E;&#x4FDD;&#x4F7F;&#x7528;&#x7684;&#x955C;&#x50CF;&#x6E90;&#x5730;&#x5740;&#x662F; npm &#x5B98;&#x65B9;&#x7684;&#x955C;&#x50CF;&#x6E90;</li>
<li><code>npm login</code> &#x767B;&#x9646;</li>
<li><code>npm publish</code> &#x53D1;&#x5E03;</li>
<li>&#x652F;&#x6301; README.md &#x6587;&#x6863;<ul>
<li>&#x6DFB;&#x52A0;&#x6587;&#x6863;&#x4E4B;&#x540E;&#x518D;&#x53D1;&#x5E03;</li>
<li>&#x9700;&#x8981;&#x66F4;&#x65B0; package.json &#x4E2D;&#x7684;&#x7248;&#x672C;&#x53F7;</li>
<li>&#x4FEE;&#x6539; package.json &#x4E0B;&#x7684; <code>&quot;description&quot;</code> &#x4E3A; &#x201C;A copy tool of a command line&#x201D;,`</li>
</ul>
</li>
<li><code>npm version patch</code> &#x66F4;&#x65B0;</li>
<li><code>npm install -g hqcopy</code> &#x5168;&#x5C40;&#x5B89;&#x88C5;&#x5230;&#x672C;&#x5730;</li>
<li><code>npm unpublish</code> &#x5220;&#x9664;</li>
</ul>
</li>
</ul>
<h3 id="Install-&#x8BF4;&#x660E;&#x6587;&#x6863;-README-md"><a href="#Install-&#x8BF4;&#x660E;&#x6587;&#x6863;-README-md" class="headerlink" title="Install &#x8BF4;&#x660E;&#x6587;&#x6863; README.md"></a>Install &#x8BF4;&#x660E;&#x6587;&#x6863; README.md</h3><p>h1 hqcopy</p>
<p>h2 Install</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ npm install --global mcopy</div></pre></td></tr></table></figure>
<p>h3 Usage</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ mcopy src des</div></pre></td></tr></table></figure>
<h3 id="&#x5C06;&#x8FD9;&#x4E2A;&#x5305;&#x6539;&#x9020;&#x4E3A;&#x672C;&#x5730;&#x548C;&#x5168;&#x5C40;&#x4E24;&#x79CD;&#x5F62;&#x5F0F;"><a href="#&#x5C06;&#x8FD9;&#x4E2A;&#x5305;&#x6539;&#x9020;&#x4E3A;&#x672C;&#x5730;&#x548C;&#x5168;&#x5C40;&#x4E24;&#x79CD;&#x5F62;&#x5F0F;" class="headerlink" title="&#x5C06;&#x8FD9;&#x4E2A;&#x5305;&#x6539;&#x9020;&#x4E3A;&#x672C;&#x5730;&#x548C;&#x5168;&#x5C40;&#x4E24;&#x79CD;&#x5F62;&#x5F0F;"></a>&#x5C06;&#x8FD9;&#x4E2A;&#x5305;&#x6539;&#x9020;&#x4E3A;&#x672C;&#x5730;&#x548C;&#x5168;&#x5C40;&#x4E24;&#x79CD;&#x5F62;&#x5F0F;</h3><p>&#x4F5C;&#x4E3A;&#x547D;&#x4EE4;&#x884C; &#x548C; &#x9879;&#x76EE;&#x5B89;&#x88C5;</p>
<p>&#x5728;&#x547D;&#x4EE4;&#x884C;&#x4E2D;&#x6267;&#x884C; index.js&#xFF0C;&#x5728;&#x4EE3;&#x7801;&#x4E2D;&#x6267;&#x884C; copy.js</p>
<ul>
<li><p>&#x5C06; package.json &#x5305;&#x4E0B;&#x7684; &#x201C;main&#x201D; &#x6539;&#x6210; &#x201C;copy.js&#x201D;</p>
</li>
<li><p>&#x5C06;&#x5DF2;&#x4E0A;&#x4F20;&#x7684; hqcopy &#x4E0B;&#x8F7D;&#x5230;&#x672C;&#x5730;&#x9879;&#x76EE;&#x4E2D;&#xFF0C;</p>
</li>
<li>&#x6253;&#x5F00;&#x4E4B;&#x540E;&#x53D1;&#x73B0; package.json &#x6587;&#x4EF6;&#x4E2D;&#x7684; main &#x5C5E;&#x6027;&#x662F; &#x201C;index.js&#x201D;</li>
<li>&#x5F53;&#x524D;&#x9879;&#x76EE;&#x4E0B; &#x65B0;&#x5EFA; .js &#x6587;&#x4EF6;, &#x7136;&#x540E;&#x4F7F;&#x7528;&#x4E0B;&#x9762;&#x4EE3;&#x7801;&#x5F15;&#x5165;&#xFF0C;&#x76EE;&#x524D;&#x53EA;&#x9650;&#x9519;&#x8BEF;</li>
<li>&#x56E0;&#x4E3A;&#x76EE;&#x524D;&#x53EA;&#x80FD;&#x5F53;&#x505A;&#x547D;&#x4EE4;&#x884C;&#x4F7F;&#x7528;</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">const</span> hqcopy = <span class="built_in">require</span>(<span class="string">&apos;hqcopy&apos;</span>);</div></pre></td></tr></table></figure>
<ul>
<li>&#x52A0;&#x8F7D;&#x673A;&#x5236;&#xFF0C;&#x9996;&#x5148;&#x53BB;&#x5F53;&#x524D;&#x9879;&#x76EE;&#x7684; node_modules,</li>
<li>&#x627E;&#x5230; hqcopy&#xFF0C;</li>
<li>&#x627E;&#x5230; package.json &#x6587;&#x4EF6;</li>
<li>&#x627E;&#x5230; main &#x5C5E;&#x6027;&#xFF0C;&#x53D1;&#x73B0;&#x662F; index.js</li>
<li>&#x5E94;&#x5F53;&#x5224;&#x65AD;&#x662F;&#x5168;&#x5C40;&#x547D;&#x4EE4;&#x884C;&#x8C03;&#x7528;&#xFF0C;&#x8FD8;&#x662F;&#x4EE3;&#x7801;&#x8C03;&#x7528;</li>
<li>&#x4FEE;&#x6539; package.json &#x6587;&#x4EF6;&#x7684; <code>main</code> &#x5C5E;&#x6027;&#x4E3A; copy.js, &#x8FD9;&#x6837;&#xFF0C;&#x5982;&#x679C;&#x662F;&#x4EE3;&#x7801;&#x8C03;&#x7528;&#xFF0C;&#x9ED8;&#x8BA4;&#x8C03;&#x7528; copy.js&#x6587;&#x4EF6;</li>
</ul>
<figure class="highlight json"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line">{</div><div class="line">  <span class="attr">&quot;name&quot;</span>: <span class="string">&quot;hqcopy&quot;</span>,</div><div class="line">  <span class="attr">&quot;version&quot;</span>: <span class="string">&quot;1.0.2&quot;</span>,</div><div class="line">  <span class="attr">&quot;description&quot;</span>: <span class="string">&quot;A copy tool of a command line&quot;</span>,</div><div class="line">  <span class="attr">&quot;main&quot;</span>: <span class="string">&quot;copy.js&quot;</span>,</div><div class="line">  <span class="attr">&quot;bin&quot;</span>: {</div><div class="line">    <span class="attr">&quot;mcopy&quot;</span>: <span class="string">&quot;./index.js&quot;</span></div><div class="line">  },</div><div class="line">  <span class="attr">&quot;scripts&quot;</span>: {</div><div class="line">    <span class="attr">&quot;test&quot;</span>: <span class="string">&quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;</span></div><div class="line">  },</div><div class="line">  <span class="attr">&quot;keywords&quot;</span>: [],</div><div class="line">  <span class="attr">&quot;author&quot;</span>: <span class="string">&quot;&quot;</span>,</div><div class="line">  <span class="attr">&quot;license&quot;</span>: <span class="string">&quot;ISC&quot;</span></div><div class="line">}</div></pre></td></tr></table></figure>
<ul>
<li>npm version patch</li>
<li>npm publish</li>
</ul>
<p>&#x65B0;&#x5EFA; test.js &#x8FDB;&#x884C;&#x6D4B;&#x8BD5;</p>
<ul>
<li><code>npm install --save hqcopy</code></li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">const</span> hqcopy = <span class="built_in">require</span>(<span class="string">&apos;hqcopy&apos;</span>);</div><div class="line">hqcopy(<span class="string">&apos;README.md&apos;</span>,<span class="string">&apos;a.md&apos;</span>, err =&gt; {</div><div class="line">  <span class="keyword">if</span> (err) {</div><div class="line">    <span class="keyword">throw</span> err;</div><div class="line">  }</div><div class="line">  <span class="built_in">console</span>.log(<span class="string">&apos;copy success&apos;</span>);</div><div class="line">});</div></pre></td></tr></table></figure>
<p>&#x73B0;&#x5728;&#x7684;&#x8FD9;&#x4E2A;&#x5305;&#x5C31;&#x65E2;&#x53EF;&#x4EE5;&#x5B89;&#x88C5;&#x5230;&#x672C;&#x5730;&#x4E5F;&#x53EF;&#x4EE5;&#x5168;&#x5C40;&#x5B89;&#x88C5;&#xFF0C;<br>&#x5B89;&#x88C5;&#x5230;&#x672C;&#x5730;&#x9879;&#x76EE;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x8BE5;&#x5305;&#x66B4;&#x9732;&#x7684; API &#x63A5;&#x53E3;&#xFF0C;<br>&#x5B89;&#x88C5;&#x5230;&#x5168;&#x5C40;&#x5C31;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x8BE5;&#x5305;&#x63D0;&#x4F9B;&#x7684;&#x5168;&#x5C40;&#x547D;&#x4EE4;&#x5DE5;&#x5177;&#x3002;</p>
<hr>
<h2 id="&#x89E3;&#x51B3;-npm-&#x88AB;&#x5899;&#x7684;&#x95EE;&#x9898;&#xFF0C;&#x4F7F;&#x7528;&#x955C;&#x50CF;&#x6E90;&#x5730;&#x5740;"><a href="#&#x89E3;&#x51B3;-npm-&#x88AB;&#x5899;&#x7684;&#x95EE;&#x9898;&#xFF0C;&#x4F7F;&#x7528;&#x955C;&#x50CF;&#x6E90;&#x5730;&#x5740;" class="headerlink" title="&#x89E3;&#x51B3; npm &#x88AB;&#x5899;&#x7684;&#x95EE;&#x9898;&#xFF0C;&#x4F7F;&#x7528;&#x955C;&#x50CF;&#x6E90;&#x5730;&#x5740;"></a>&#x89E3;&#x51B3; npm &#x88AB;&#x5899;&#x7684;&#x95EE;&#x9898;&#xFF0C;&#x4F7F;&#x7528;&#x955C;&#x50CF;&#x6E90;&#x5730;&#x5740;</h2><p>&#x56FD;&#x5185;&#x7684;&#x6DD8;&#x5B9D;&#xFF1A;&#x514B;&#x9686;&#x4E86;&#x56FD;&#x5916;&#x7684;&#x670D;&#x52A1;&#x5668;&#xFF0C;<br>&#x8DDF;&#x56FD;&#x5916;&#x7684; npm &#x6BCF;10&#x5206;&#x949F;&#x4FDD;&#x6301;&#x540C;&#x6B65;&#x4E00;&#x6B21;&#xFF1B;</p>
<ul>
<li><code>npm install &#x5305;&#x540D; --registry=https://registry.npm.taobao.org</code> &#x56FD;&#x5185;&#x6DD8;&#x5B9D;&#x955C;&#x50CF;&#x6E90;&#x5730;&#x5740;</li>
<li><code>npm config set registry=https://registry.npm.taobao.org</code> <ul>
<li>&#x8FD9;&#x662F;&#x5C06; npm &#x7684;&#x4E0B;&#x8F7D;&#x955C;&#x50CF;&#x6E90;&#x5730;&#x5740;&#x6539;&#x4E3A;&#x6DD8;&#x5B9D;&#x7684; cpnm &#x955C;&#x50CF;&#x6E90;</li>
<li>&#x8FD9;&#x6837;&#x6267;&#x884C;&#x8BE5;&#x547D;&#x4EE4;&#xFF0C;&#x4EE5;&#x540E;&#x6240;&#x6709;&#x7684; install &#x90FD;&#x4F1A;&#x901A;&#x8FC7;&#x6307;&#x5B9A;&#x7684;&#x5730;&#x5740;&#x4E0B;&#x8F7D;</li>
<li>&#x8FD8;&#x63D0;&#x4F9B;&#x4E86; cnpm &#x547D;&#x4EE4;</li>
<li><code>npm install -g cnpm</code><ul>
<li>&#x5B89;&#x88C5;&#x4E86; cnpm &#x4E4B;&#x540E;&#xFF0C;&#x5C31;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; cnmp &#x547D;&#x4EE4;&#x5B89;&#x88C5;&#x548C;&#x7BA1;&#x7406;&#x5305;&#x4E86;</li>
<li>cnpm &#x9ED8;&#x8BA4; &#x5C31;&#x4F1A;&#x8D70;&#x6DD8;&#x5B9D;&#x7684; npm &#x955C;&#x50CF;&#x6E90;&#x5730;&#x5740;</li>
<li><code>cnpm install -g &#x5305;&#x540D;</code></li>
<li><code>cnpm install &#x5305;&#x540D;</code></li>
<li>npm &#x7684;&#x547D;&#x4EE4;&#x90FD;&#x53EF;&#x4EE5;&#x901A;&#x8FC7; cnpm &#x6765;&#x4EE3;&#x66FF;</li>
</ul>
</li>
</ul>
</li>
<li>&#x5B9E;&#x9645;&#x4E0A;&#xFF0C;&#x5728;&#x7528;&#x6237;&#x76EE;&#x5F55;&#x4E0B;&#x751F;&#x6210;&#x4E86;.npmrc &#x6587;&#x4EF6;&#xFF0C;&#x4FDD;&#x5B58;&#x4E86;&#x955C;&#x50CF;&#x6E90;&#x5730;&#x5740;<ul>
<li>&#x901A;&#x8FC7;&#x4FEE;&#x6539;&#x6B21;&#x5730;&#x5740;&#x4E5F;&#x53EF;&#x4EE5;&#x3002;</li>
</ul>
</li>
<li>&#x8FD8;&#x6709;&#x4E00;&#x4E2A;&#x5DE5;&#x5177;&#xFF0C;&#x5982;&#x679C;&#x5728;&#x5C40;&#x57DF;&#x7F51;&#x5185;&#xFF0C;&#x5C40;&#x57DF;&#x7F51;&#x7684;&#x5305;&#xFF0C;&#x8FD9;&#x6837;&#x53C8;&#x9700;&#x8981;&#x6539;&#x955C;&#x50CF;&#x6E90;&#x5730;&#x5740;&#xFF1A;<ul>
<li>&#x5B89;&#x88C5;&#x548C;&#x7BA1;&#x7406;&#x591A;&#x4E2A;&#x955C;&#x50CF;&#x6E90;&#x5730;&#x5740;</li>
<li><code>npm install -g nrm</code> &#x4E0B;&#x8F7D;&#x5B89;&#x88C5;<ul>
<li>nrm &#x5373; nmp registry manager</li>
<li>nrm &#x53EF;&#x4EE5;&#x7528;&#x6765;&#x7BA1;&#x7406;&#x591A;&#x4E2A;&#x955C;&#x50CF;&#x6E90;&#x5730;&#x5740;&#xFF0C;&#x5207;&#x6362;&#x591A;&#x4E2A;&#x955C;&#x50CF;&#x6E90;&#x5730;&#x5740;</li>
<li>nrm &#x662F;&#x57FA;&#x4E8E; node &#x5F00;&#x53D1;&#x7684;</li>
<li><code>nrm ls</code> &#x5217;&#x51FA;&#x6240;&#x6709;&#x7684;&#x955C;&#x50CF;&#x6E90;&#x5730;&#x5740;</li>
<li><code>nrm current</code> &#x663E;&#x793A;&#x5F53;&#x524D;&#x4F7F;&#x7528;&#x7684;&#x955C;&#x50CF;&#x6E90;&#x5730;&#x5740;</li>
<li><code>nrm use &#x955C;&#x50CF;&#x6E90;&#x540D;&#x79F0;</code> &#x5207;&#x6362;&#x5230;&#x6307;&#x5B9A;&#x7684;&#x955C;&#x50CF;&#x6E90;&#x5730;&#x5740;</li>
<li><code>nrm add &#x955C;&#x50CF;&#x6E90;&#x540D;&#x79F0; &#x955C;&#x50CF;&#x6E90;&#x5730;&#x5740;</code> &#x6DFB;&#x52A0;&#x6307;&#x5B9A;&#x7684;&#x955C;&#x50CF;&#x6E90;&#x5730;&#x5740;</li>
<li><code>nrm del &#x955C;&#x50CF;&#x6E90;&#x540D;&#x79F0;</code> &#x4ECE;&#x672C;&#x5730;&#x5220;&#x9664;&#x6307;&#x5B9A;&#x7684;&#x955C;&#x50CF;&#x6E90;&#x5730;&#x5740;</li>
<li>&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x90FD;&#x5728;&#x7528;&#x6237;&#x76EE;&#x5F55;&#x4E0B;&#xFF0C;&#x53EB; .nrmrc&#xFF0C; &#x76F4;&#x63A5;&#x4FEE;&#x6539;&#x6B64;&#x6587;&#x4EF6;&#x4E5F;&#x53EF;&#x914D;&#x7F6E;&#xFF1B;</li>
</ul>
</li>
</ul>
</li>
</ul>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        
  <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
    <div>坚持原创技术分享，您的支持将是我最大的鼓励！</div>
    <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
      <span>赏</span>
    </button>
    <div id="QR" style="display: none;">
      
        <div id="wechat" style="display: inline-block">
          <img id="wechat_qr" src="http://ofy7k3v4s.bkt.clouddn.com/wcpayCode.jpg" alt="Hongqin Ma WeChat Pay"/>
          <p>微信打赏</p>
        </div>
      
      
        <div id="alipay" style="display: inline-block">
          <img id="alipay_qr" src="http://ofy7k3v4s.bkt.clouddn.com/apayCode.jpg" alt="Hongqin Ma Alipay"/>
          <p>支付宝打赏</p>
        </div>
      
    </div>
  </div>


      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/tools/" rel="tag">#tools</a>
          
            <a href="/tags/npm/" rel="tag">#npm</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2016/11/02/Anisina-博客主题使用心得/" rel="next" title="Anisina 博客主题使用心得">
                <i class="fa fa-chevron-left"></i> Anisina 博客主题使用心得
              </a>
            
          </div>

          <div class="post-nav-prev post-nav-item">
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
        <div class="ds-share flat" data-thread-key="2016/11/09/t9-npm/"
     data-title="npm, Node Package Manager"
     data-content=""
     data-url="https://hongqinma.github.io/2016/11/09/t9-npm/">
  <div class="ds-share-inline">
    <ul  class="ds-share-icons-16">

      <li data-toggle="ds-share-icons-more"><a class="ds-more" href="javascript:void(0);">分享到：</a></li>
      <li><a class="ds-weibo" href="javascript:void(0);" data-service="weibo">微博</a></li>
      <li><a class="ds-qzone" href="javascript:void(0);" data-service="qzone">QQ空间</a></li>
      <li><a class="ds-qqt" href="javascript:void(0);" data-service="qqt">腾讯微博</a></li>
      <li><a class="ds-wechat" href="javascript:void(0);" data-service="wechat">微信</a></li>

    </ul>
    <div class="ds-share-icons-more">
    </div>
  </div>
</div>
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
      <div class="ds-thread" data-thread-key="2016/11/09/t9-npm/"
           data-title="npm, Node Package Manager" data-url="https://hongqinma.github.io/2016/11/09/t9-npm/">
      </div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            Table of Contents
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            Overview
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel ">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="//schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/photo.jpg"
               alt="Hongqin Ma" />
          <p class="site-author-name" itemprop="name">Hongqin Ma</p>
          <p class="site-description motion-element" itemprop="description">Spell at all costs， to rush you in the future. </p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">22</span>
              <span class="site-state-item-name">posts</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              <a href="/categories">
                <span class="site-state-item-count">3</span>
                <span class="site-state-item-name">categories</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">13</span>
                <span class="site-state-item-name">tags</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/HongqinMa" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://twitter.com/HongqinMa" target="_blank" title="Twitter">
                  
                    <i class="fa fa-fw fa-twitter"></i>
                  
                  Twitter
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://www.facebook.com/profile.php?id=100006581058735" target="_blank" title="Facebook">
                  
                    <i class="fa fa-fw fa-facebook"></i>
                  
                  Facebook
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://www.zhihu.com/people/HirakuMa" target="_blank" title="知乎">
                  
                    <i class="fa fa-fw fa-share-alt"></i>
                  
                  知乎
                </a>
              </span>
            
          
        </div>

        
        

        
        
          <div class="links-of-blogroll motion-element links-of-blogroll-inline">
            <div class="links-of-blogroll-title">
              <i class="fa  fa-fw fa-globe"></i>
              Links
            </div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.cnblogs.com/rubylouvre/" title="司徒正美" target="_blank">司徒正美</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.cnblogs.com/sanshi/" title="三生石上" target="_blank">三生石上</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.cnblogs.com/TomXu/" title="汤姆大叔" target="_blank">汤姆大叔</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://gold.xitu.io/" title="掘金" target="_blank">掘金</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://segmentfault.com/" title="segmentfault" target="_blank">segmentfault</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.jianshu.com/users/1cbb94e5ed4d/latest_articles" title="简书" target="_blank">简书</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://home.cnblogs.com/" title="博客园" target="_blank">博客园</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://www.awesomes.cn/" title="Awesomes" target="_blank">Awesomes</a>
                </li>
              
            </ul>
          </div>
        

      </section>

      
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">
            
              
            
            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#npm-有两层含义："><span class="nav-number">1.</span> <span class="nav-text">npm 有两层含义：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#安装-npm"><span class="nav-number">2.</span> <span class="nav-text">安装 npm</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#npm-基本使用"><span class="nav-number">3.</span> <span class="nav-text">npm 基本使用</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#本地安装"><span class="nav-number">3.1.</span> <span class="nav-text">本地安装</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#包说明文件：package-json"><span class="nav-number">3.2.</span> <span class="nav-text">包说明文件：package.json</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#本地安装常用命令"><span class="nav-number">3.3.</span> <span class="nav-text">本地安装常用命令</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#全局安装"><span class="nav-number">3.4.</span> <span class="nav-text">全局安装</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#常用命令"><span class="nav-number">3.4.1.</span> <span class="nav-text">常用命令</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#如何将包发布到-npm-网站上并且通过-npm-install-global-包名-安装"><span class="nav-number">4.</span> <span class="nav-text">如何将包发布到 npm 网站上并且通过 npm install --global 包名 安装</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#配置原理"><span class="nav-number">4.1.</span> <span class="nav-text">配置原理</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#node-提供了一个更方便的方式自动生成-cmd-文件以及和需要发布的文件产生关联"><span class="nav-number">4.2.</span> <span class="nav-text">node 提供了一个更方便的方式自动生成 .cmd 文件以及和需要发布的文件产生关联</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Install-说明文档-README-md"><span class="nav-number">4.3.</span> <span class="nav-text">Install 说明文档 README.md</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#将这个包改造为本地和全局两种形式"><span class="nav-number">4.4.</span> <span class="nav-text">将这个包改造为本地和全局两种形式</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#解决-npm-被墙的问题，使用镜像源地址"><span class="nav-number">5.</span> <span class="nav-text">解决 npm 被墙的问题，使用镜像源地址</span></a></li></ol></div>
            
          </div>
        </section>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2016</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Hongqin Ma</span>
</div>

<div class="powered-by">
  Powered by <a class="theme-link" href="https://hexo.io">Hexo</a>
</div>

<div class="theme-info">
  Theme -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Muse
  </a>
</div>

<script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<span id="busuanzi_container_site_pv">
    &nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;Page Views: <span id="busuanzi_value_site_pv"></span> 
</span>

        

<div class="busuanzi-count">

  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv"><i class="fa fa-user"></i><span class="busuanzi-value" id="busuanzi_value_site_uv"></span></span>
  

  
    <span class="site-pv"><i class="fa fa-eye"></i><span class="busuanzi-value" id="busuanzi_value_site_pv"></span></span>
  
  
</div>



        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.0.2"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.0.2"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.0.2"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.0.2"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.0.2"></script>



  

  
    
  

  <script type="text/javascript">
    var duoshuoQuery = {short_name:"Hiraku"};
    (function() {
      var ds = document.createElement('script');
      ds.type = 'text/javascript';ds.async = true;
      ds.id = 'duoshuo-script';
      ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
      ds.charset = 'UTF-8';
      (document.getElementsByTagName('head')[0]
      || document.getElementsByTagName('body')[0]).appendChild(ds);
    })();
  </script>

  
    
    <script src="/lib/ua-parser-js/dist/ua-parser.min.js?v=0.7.9"></script>
    <script src="/js/src/hook-duoshuo.js"></script>
  






  
  

  

  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.1.js"></script>
  <script>AV.initialize("PPmoIQxeu8Sd21h6Tl9TthNx-gzGzoHsz", "rTvbY2H7DvWzRipiBwn72RQ4");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  

  
  
  <!-- custom analytics part create by xiamo -->
<script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.1.js"></script>
<script>AV.initialize("PPmoIQxeu8Sd21h6Tl9TthNx-gzGzoHsz", "rTvbY2H7DvWzRipiBwn72RQ4");</script>
<script>
function showTime(Counter) {
  var query = new AV.Query(Counter);
  $(".leancloud_visitors").each(function() {
    var url = $(this).attr("id").trim();
    query.equalTo("url", url);
    query.find({
      success: function(results) {
        if (results.length == 0) {
          var content = '0 ' + $(document.getElementById(url)).text();
          $(document.getElementById(url)).text(content);
          return;
        }
        for (var i = 0; i < results.length; i++) {
          var object = results[i];
          var content = object.get('time') + ' ' + $(document.getElementById(url)).text();
          $(document.getElementById(url)).text(content);
        }
      },
      error: function(object, error) {
        console.log("Error: " + error.code + " " + error.message);
      }
    });

  });
}

function addCount(Counter) {
  var Counter = AV.Object.extend("Counter");
  url = $(".leancloud_visitors").attr('id').trim();
  title = $(".leancloud_visitors").attr('data-flag-title').trim();
  var query = new AV.Query(Counter);
  query.equalTo("url", url);
  query.find({
    success: function(results) {
      if (results.length > 0) {
        var counter = results[0];
        counter.fetchWhenSave(true);
        counter.increment("time");
        counter.save(null, {
          success: function(counter) {
            var content =  counter.get('time') + ' ' + $(document.getElementById(url)).text();
            $(document.getElementById(url)).text(content);
          },
          error: function(counter, error) {
            console.log('Failed to save Visitor num, with error message: ' + error.message);
          }
        });
      } else {
        var newcounter = new Counter();
        newcounter.set("title", title);
        newcounter.set("url", url);
        newcounter.set("time", 1);
        newcounter.save(null, {
          success: function(newcounter) {
              console.log("newcounter.get('time')="+newcounter.get('time'));
            var content = newcounter.get('time') + ' ' + $(document.getElementById(url)).text();
            $(document.getElementById(url)).text(content);
          },
          error: function(newcounter, error) {
            console.log('Failed to create');
          }
        });
      }
    },
    error: function(error) {
      console.log('Error:' + error.code + " " + error.message);
    }
  });
}
$(function() {
  var Counter = AV.Object.extend("Counter");
  if ($('.leancloud_visitors').length == 1) {
    addCount(Counter);
  } else if ($('.post-title-link').length > 1) {
    showTime(Counter);
  }
}); 
</script>

  
</body>
</html>
